using System.ComponentModel;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;

[assembly: WebResource("jQueryNET.ComboBox.ComboBox.css", "text/css", PerformSubstitution = true)]
[assembly: WebResource("jQueryNET.ComboBox.ComboBox.js", "application/x-javascript", PerformSubstitution = true)]

[assembly: WebResource("jQueryNET.ComboBox.Images.trigger.gif", "image/gif")]

namespace jQueryNET
{
	[RequiredScript(typeof(ScriptResources), 0)]
	[RequiredScript(typeof(Common), 1)]
	[RequiredScript(typeof(JQueryScript), 2)]
	[RequiredScript(typeof(Utils), 3)]
	[ClientCssResource("jQueryNET.Common.Common.css")]
	[ClientCssResource("jQueryNET.ComboBox.ComboBox.css")]
	[ClientScriptResource("jQueryNET.Controls.ComboBox", "jQueryNET.ComboBox.ComboBox.js")]
	[ToolboxBitmap(typeof(ComboBox), "ComboBox.ComboBox.ico")]
	public class ComboBox : DataControlBase
	{
		#region Public constructors

		/// <summary>
		/// 
		/// </summary>
		public ComboBox()
			: base(true, HtmlTextWriterTag.Div)
		{
			Items = new ComboBoxItemCollection();
		}

		#endregion

		#region Public properties

		[Description("Gets the selected item in the list contror")]
		[Category("Behavior")]
		[ExtenderControlProperty]
		[ClientPropertyName("selectedItem")]
		public ComboBoxItem SelectedItem
		{
			get
			{
				var result = ViewState["SelectedItem"];
				if (result != null)
					return (ComboBoxItem)result;

				return null;
			}
		}

		[DefaultValue(-1)]
        [Description("Gets or sets the index of the selected item in the ComboBox control.")]
		[Category("Behavior")]
		[ExtenderControlProperty]
		[ClientPropertyName("selectedIndex")]
		public int SelectedIndex
		{
			get { return (int)(ViewState["selectedIndex"] ?? -1); }
			set { ViewState["selectedIndex"] = value; }
		}

		[Description("Gets the value of the selected item in the list control, or selects the item in the list control that contains the specified value.")]
		[Category("Behavior")]
		[ExtenderControlProperty]
		[ClientPropertyName("selectedValue")]
		public string SelectedValue
		{
			get { return (string)(ViewState["selectedValue"] ?? string.Empty); }
			set { ViewState["selectedValue"] = value; }
		}

		[ExtenderControlProperty]
		[ClientPropertyName("enabled")]
		public override bool Enabled
		{
			get
			{
				return base.Enabled;
			}
			set
			{
				base.Enabled = value;
			}
		}

		[Description("Items of combobox")]
		[Category("Behavior")]
		[ExtenderControlProperty(true, true)]
		[ClientPropertyName("items")]
		public ComboBoxItemCollection Items { get; private set; }

		/// <summary
		/// 
		/// </summary>
		[DefaultValue("")]
		[Category("Behavior")]
		[ExtenderControlEvent]
		[ClientPropertyName("selectItemChange")]
		public string SelectItemChange
		{
			get { return (string)(ViewState["SelectItemChange"] ?? string.Empty); }
			set { ViewState["SelectItemChange"] = value; }
		}

		#endregion
	}
}